import cityCascader from '../../../component/cityCascader/index.vue'
export default {
  name: "ordinary",
  components: {
    tab: () => import("../../../component/tab/index.vue"),
    cityCascader
  },
  data() {
    return {
      tabs: [{
          label: "专用发票",
          status: "1"
        },
        {
          label: "普通发票",
          status: "2"
        }
      ],
      statusOptions: [{
          label: "全部",
          status: ""
        },
        {
          label: "成功",
          status: "1"
        },
        {
          label: "失败",
          status: "2"
        }
      ],
      form: {
        type: "2", // 普通发票
        // status: "0", // 待开票
        result: "", // 全部
        starttime: "",
        endtime: "",
        companyname: "",
        province: '',
        city: '',
        area: '',
        pagenum: 1,
        pagesize: 10
      },
      provinceList: [],
      cityList: [],
      areaList: [],
      total: 0,
      tableData: [],
      loading: false,
      region:[]
    };
  },
  created() {
    this.getTableData();
  },
  methods: {
    handleCityChange (val) {
      this.form.province = val[0];
      this.form.city = val[1];
      this.form.area = val[2];
    },
    // 时间比较
    compareDate() {
      let starttime = Date.parse(this.form.starttime);
      let endtime = Date.parse(this.form.endtime);
      if (starttime > endtime) {
        this.$message({
          message: '开始时间不能大于结束时间',
          type: 'error'
        });
        return false;
      } else {
        return true;
      }
    },
    getTableData() {
      if (!this.compareDate()) {
        return
      } else {
        this.loading = true;
        this.$axios.post("/app/v1/platform/invoice/applyList", this.form).then(res => {
          this.loading = false;
          if (res.data.code === 1) {
            this.tableData = res.data.data.list;
            this.total = +res.data.data.totalnum;
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            })
          }
        })
      }
    },
    // 查询
    query() {
      this.form.pagenum = 1;
      this.getTableData();
    },
    // 下载发票
    download(url) {
      let link = document.createElement('a');
      link.style.display = 'none';
      link.href = url;
      link.setAttribute('download', '发票');
      link.setAttribute('target', '_Blank');
      document.body.appendChild(link);
      link.click();
    },
    // 分页
    handleCurrentChange(val) {
      this.form.pagenum = val;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.form.pagenum = 1;
      this.form.pagesize = val;
      this.getTableData();
    }
  }
};